<!--
 * @Author: lee
 * @Date: 2024-01-16 09:13:14
 * @LastEditors: lee
 * @LastEditTime: 2024-01-16 14:12:27
 * @Description: file content
-->
<template>
  <div>
    <p>
      邮箱：
      <input type="text" v-model="form.email" />
    </p>
    <p>
      用户名：
      <input type="text" v-model="form.username" />
    </p>
    <p>
      密码：
      <input type="text" v-model="form.password" />
    </p>
    <p>
      <button @click="login" type="button">登录</button>
    </p>
  </div>
</template>
<script>
export default {
  data() {
    return {
      form: {
        email: "",
        name: "",
        password: ""
      }
    };
  },
  methods: {
    async login() {
      //自定义接口示例，需要后端做跨域处理
      // let res = await this.$testAPI.getHome()
      // console.log('res--',res)

      let res = await this.$axios.post(
        "https://api.realworld.io/api/users/login",
        { user: this.form }
      );
      let { token, username, image } = res.user;
      this.$store.dispatch("setToken", token);
      this.$store.dispatch("setName", username);
      this.$store.dispatch("setAvatar", image);
      this.$router.push("/");
    }
  }
};
</script>